<?php
class stat_susheControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		
		$data=M("ymdian_order")->getAll("select count(order_id) as num,sushe From ".table('ymdian_order')." where shopid=".SHOPID." group by sushe ");
		$d2=M("ymdian_order")->getAll("select count(userid) as unum,sushe From ".table('ymdian_order')." where shopid=".SHOPID." group by sushe,userid ");
		if($d2){
			foreach($d2 as $d){
				$u[$d['sushe']]+=$d['unum'];
			}
		}
		$unums=array();
		$nums=array();
		$sushes=array(); 
		if($data){
			foreach($data as $k=>$v){
				$u=M("ymdian_order")->getAll("select userid From ".table('ymdian_order')." where shopid=".SHOPID." AND sushe=".$v['sushe']." group by userid ");
				$v['unum']=count($u);
				$unums[$k]=$v['unum'];
				$nums[$k]=$v['num'];
				$sushes[$k]=$v['sushe'];
				$data[$k]=$v;
			}
			
		 
		switch(get('orderby')){
				case "order": 
						if(get('index')=='asc'){
							 
							array_multisort ( $nums ,  SORT_ASC  , $data ); 
						}else{
							array_multisort ( $nums ,  SORT_DESC,$data );
						}
					break;
				case 'sushe':
						if(get('index')=='asc'){
							 
							array_multisort ( $sushes ,  SORT_ASC  , $data ); 
						}else{
							array_multisort ( $sushes ,  SORT_DESC,$data );
						}
					break;
			}
	 	}
		$this->smarty->assign(array(
			"data"=>$data,
			"baseurl"=>APPYMDIAN."?m=stat_sushe"
		));
		$this->smarty->display("stat_sushe/index.html");
	}
}
?>